<template>
  <div>
    <el-dialog :title="title" :visible.sync="visible" width="1000px" append-to-body custom-class="import-dialog"
      :show-close="closeable" :close-on-click-modal="closeable" :close-on-press-escape="closeable">
      <el-row :gutter="10">
        <el-col :span="8" v-for="(item, index) in list" :key="index">
          <div class="enterpriseItem" :class="{ 'current': current === index }" @click.stop="select(item,index)">
            <div class="logo">
              <img :src="item.icon?item.icon:defaultImg" width="100%" alt="" srcset="">
            </div>
            <div class="title">{{ item.tenantName }}</div>
          </div>
        </el-col>
      </el-row>

      <div slot="footer" class="dialog-footer" style="text-align: center">
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
// import { updatePassword } from "@/api/sys-enterprise/account";
export default {
  props: {
    title: {
      default: "请选择登录企业",
    },
    value: {
      default: false,
    },
    userId: {
      default: undefined,
    },
  },
  data() {
    return {
      visible: false,
      closeable: true,
      current: 0,
      defaultImg: require('@/assets/images/moren.jpg'),
      callback: function () { },
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 总条数
      total: 0,
      //列表
      list: [],
      id: "",
    };
  },
  computed:{

  },
  watch: {
    value(newVal, oldVal) {
      if (newVal) {
        this.init();
      }
      this.visible = newVal; // 监测value的变化，并赋值。
    },
    visible(val) {
      this.$emit("input", val); // 此处监测visible目的为关闭弹窗时，重新更换value值，注意emit的事件一定要为input。
    },
    id(newVal, oldVal) {
      let index = this.list.findIndex(item => item.tenantId === newVal)
      if (index !== -1) {
        this.current = index
      }
    }
  },
  created() {
  },
  methods: {
    init() {
      this.reset()
    },
    reset() {
      this.resetForm("form");
    },
    submitForm() {
      this.callback(this.list[this.current])
      this.visible = false
    },
    cancel() {
      this.reset();
      this.visible = false;
    },
    select(item,index){
      this.current = index
    }
  },
};
</script>

<style lang="scss" scoped>
//弹出层的高度
.import-dialog {
  height: auto;
  max-height: 80vh;
  overflow-y: auto;
}

//弹出层里内容的高度
::v-deep .el-dialog__body {
  max-height: 80vh !important;
  overflow-y: auto;
}

.enterpriseItem {
  display: flex;
  align-items: center;
  padding: 10px;
  cursor: pointer;

  &.current {
    background: #eee;
    cursor: default;
  }

  .logo {
    width: 80px;
    height: 80px;
    margin-right: 10px;
  }

  .title {
    font-size: 16px;
    font-weight: 700;
  }
}
</style>
